package cn.itheima.service.impl;

import cn.itheima.mapper.UserMapper;
import cn.itheima.pojo.User;
import cn.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public Map pageQuery(Integer pageNum, Integer pageSize) {
        List<User> userlist  =  userMapper.pageQuery((pageNum-1)*pageSize,pageSize);
        // select * from  xx limit  ?,?
        long  total  = userMapper.findTotalCounts();
        //  select count(1) from  xxx
        Map map = new HashMap();
        map.put("userlist",userlist);
        map.put("total",total);
        return map;
    }
}
